import React from "react";
import { Link, Routes, Route, Outlet } from "react-router-dom";

const Home111 = () => {
  return <div>这是首页111</div>;
};
const Home222 = () => {
  return <div>这是首页222</div>;
};

const Home = () => {
  return (
    <>
      <div>这是首页</div>
      <ul>
        <li>
          <Link to="/home/home111">首页111</Link>
        </li>
        <li>
          <Link to="/home/home222">首页222</Link>
        </li>
      </ul>

      <hr />

      {/* 表示的路由出口，相当于vue的router-view */}
      <Outlet />
    </>
  );
};
const About = () => {
  return <div>这是关于页</div>;
};

const App = () => {
  return (
    <>
      <h2>router-v6-nest</h2>
      <ul>
        <li>
          <Link to="/home">首页</Link>
        </li>
        <li>
          <Link to="/about">关于页</Link>
        </li>
      </ul>

      <hr />

      <Routes>
        <Route path="/home" element={<Home />}>
          {/* path不是以"/"开头的，那么就是在上一级的基础上拼接 */}
          {/* index表示这个路由和上一级的路由，路径相同 */}
          <Route index element={<Home111 />}></Route>
          <Route path="home222" element={<Home222 />}></Route>
        </Route>
        <Route path="/about" element={<About />}></Route>
      </Routes>
    </>
  );
};

export default App;
